package com.boss.salary.dao.impl;

import com.alibaba.druid.util.StringUtils;
import com.boss.framework.dao.BaseDaoImpl;
import com.boss.salary.constant.TableName;
import com.boss.salary.dao.ISalaryWarnMonthDao;
import com.boss.salary.entity.SalaryWarnMonth;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class SalaryWarnMonthDaoImpl extends BaseDaoImpl implements ISalaryWarnMonthDao {
    @Override
    public void updateSalaryWarnMonth(SalaryWarnMonth salaryWarnMonth) {
        StringBuilder sql = new StringBuilder();
        sql.append(" update ").append(TableName.SALARY_WARN_MONTH)
                .append(" set create_time=?, update_time=?, warn_month=?  where id=?");
        Object[] params = new Object[]{
                salaryWarnMonth.getCreateTime(), salaryWarnMonth.getUpdateTime(), salaryWarnMonth.getWarnMonth(), salaryWarnMonth.getId()
        };
        this.getJdbcTemplate().update(sql.toString(), params);
    }

    @Override
    public SalaryWarnMonth getSalaryWarnMonth(String province) {
        StringBuilder sql = new StringBuilder();
        sql.append("select id,create_time, update_time, warn_month from ").append(TableName.SALARY_WARN_MONTH);
        List<Object> paramList = new ArrayList<>();
        if (!StringUtils.isEmpty(province)) {
            sql.append(" where mof_div_code = ?");
            paramList.add(province);
        }
        SalaryWarnMonth swm = this.getjdbcTemplate().queryForObject(sql.toString(), new BeanPropertyRowMapper<>(SalaryWarnMonth.class), paramList.toArray());//, paramList.toArray()
        return swm;
    }
}
